# -*- coding: utf-8 -*-
"""
@Time : 2024/3/6 8:37 PM
@Author: imamhusan
@Des: TCP 服务端
"""
import socket

# 创建TCP 套接字
server_socket = socket.socket()

# 绑定ip
server_socket.bind(('192.168.1.156', 1128))

# 监听
server_socket.listen(1)

print('TCP 服务器已启动， 等待客户连接...')

client_socket, addr = server_socket.accept()

while True:
    # 接收数据
    data = client_socket.recv(1024).decode()
    print(f'来自于：{addr} 信息内容：{data}')

    if data == 'q':
        client_socket.close()
        break

    send_msg = input('请输入回复内容：')
    client_socket.sendall(send_msg.encode())

# 关闭连接
server_socket.close()















